<template>
	<view class="edit-info">
		<view class="create-project-form">
			<view class="create-item">
				<text class="info-item-title">节点名称</text>
				<input class="info-item-input" type="text" placeholder-class="placeholderFontClass"
					placeholder="请输入节点名称" v-model="nodeName">
			</view>

			<view class="create-item">
				<text class="info-item-title">维系单位</text>
				<input class="info-item-input" type="text" @click="handleOpenUnitsPopup"
					placeholder-class="placeholderFontClass" disabled readonly placeholder="请选择维系单位" v-model="units">
				<uni-icons class="right-arrow-icon" type="forward" size="14" color="#999"></uni-icons>
			</view>

			<view class="create-item">
				<text class="info-item-title">维系时间</text>
				<input class="info-item-input" type="text" placeholder-class="placeholderFontClass"
					placeholder="请输入维系时间" v-model="nodeNum">
			</view>




		</view>
		<button class="create-btn" @click.stop.prevent="handleSubmit">确认创建</button>

		<!-- 职位popup -->
		<van-popup :show="unitsPopShow" position="bottom">
			<van-picker show-toolbar :columns="unitsList" @confirm="onUnitsConfirm" @cancel="unitsPopShow = false" />
		</van-popup>
	</view>
</template>

<script>
	import apiRqs from "@/api/api-request.js";
	export default {
		data() {
			return {
				nodeName: '',
				nodeNum: '',
				units: "-",
				unitsList: ['-', '+'],
				unitsPopShow: false,
				tokenInfo: {},
			}
		},
		onShow() {},
		methods: {
			handleOpenUnitsPopup() {
				this.unitsPopShow = true;
			},
			onUnitsConfirm(value) {
				this.units = value.detail.value;
				this.unitsPopShow = false;
			},
			handleSubmit() {
				let {
					nodeName,
					nodeNum,
					units
				} = this;
				if (nodeName.trim() == "") {
					getApp().showToast('节点名称不能为空');
					return false;
				} else if (nodeNum.trim() == "") {
					getApp().showToast('维系时间不能为空');
					return false;
				} else {
					getApp().showLoading();
					const node = (units + nodeNum) * 1;
					var that = this;
					let rqs = {
						"node": node,
						"subject": nodeName
					};
					console.log('提交数据', rqs);
					apiRqs._addNode(rqs).then((res) => {
						console.log('创建结果', res);
						uni.hideLoading();
						if (res.code == 200) {
							getApp().showToast("创建成功", "success");
							setTimeout(() => {
								uni.navigateBack();
							}, 1500)
						} else {
							getApp().showToast(res.msg);
						}
					}).catch((err) => {
						console.log('err', err);
					})
				}

			},
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f5f5f5;
	}

	.edit-info {
		.create-project-form {
			margin: 20px;

			.create-item {
				display: flex;
				align-items: center;
				width: 100%;
				border-bottom: 1px solid #f5f5f5;
				background-color: #fff;
				padding: 16px 15px;
				box-sizing: border-box;
				position: relative;

				.right-arrow-icon {
					position: absolute;
					right: 10px;
				}

				&:first-child {
					border-top: 1px solid #f5f5f5;
					border-top-left-radius: 4px;
					border-top-right-radius: 4px;
				}

				&:last-child {
					border-bottom-left-radius: 4px;
					border-bottom-right-radius: 4px;
				}

				.info-item-title {
					width: 80px;
					flex: 0 0 80px;
					font-size: 14px;
				}

				.info-item-input {
					flex: 1;
					font-size: 14px;
					text-align: left;
					color: #666666;
				}

				.placeholderFontClass {
					color: #ddd;
				}
			}


		}

		.create-btn {
			margin: 20px;
			border: none;
			background-color: #008aff;
			color: #fff;
			font-size: 15px;
			height: 35pt;
			line-height: 35pt;

			&::after {
				border: none;
			}

			&:active {
				background-color: #0076DB;
			}
		}
	}
</style>
